﻿using System;
using System.Collections.Generic;

namespace KxParser.Lexer
{
	/// <summary>
	/// This class represents string of one or more characters which represents some recognized rule
	/// </summary>
	/// <see cref="http://en.wikipedia.org/wiki/Token_%28parser%29#Token"/>
	[Obsolete("Use TokenEx instead")]
    public class Token
    {
		/// <summary>
		/// Token name
		/// </summary>
		public string Name { get; set; }

		/// <summary>
		/// MultiToken support - for more than one token with same content. System will not create new token, but add AdditionalName to existing token
		/// </summary>
		public List<string> AdditionalNames { get; set; }

		/// <summary>
		/// Tokens full name - represents combination of Name and AdditionalNames
		/// </summary>
		public string FullName
		{
			get
			{
				string fullName = Name;
				foreach (string addName in AdditionalNames)
				{
					fullName += KxParserGlobal.TokenNameSeparator + addName;
				}
				return fullName;
			}
		}

        /// <summary>
        /// Token content
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// Is token ignored
        /// </summary>
        public bool IsIgnored { get; set; }


        /// <summary>
        /// Tokens line number
        /// </summary>
        public int LineNumber { get; set; }

        /// <summary>
        /// Tokens start index (in line)
        /// </summary>
        public int StartIndex { get; set; }

        /// <summary>
        /// Tokens end index (in line)
        /// </summary>
        public int EndIndex { get; set; }

        /// <summary>
        /// Tokens total index (position from first line, first character)
        /// </summary>
        public int TotalIndex { get; set; }


		public Token()
		{
			AdditionalNames = new List<string>();
		}

        public override string ToString()
        {
            return string.Format("{0}='{1}',[{2}-{3}][{4}-{5}] {6}", FullName , Content, StartIndex, EndIndex, TotalIndex, TotalIndex + (EndIndex - StartIndex), (IsIgnored) ? " - IGNORED" : "");
        }
    }
}
